Serialize to binary