Ejemplo n.º 1
0
func (self *channelAPI) Blob_Mutation(perma grapher.PermaNode, mutation grapher.MutationNode) {
	mutJson := map[string]interface{}{"perma": perma.BlobRef(), "seq": mutation.SequenceNumber(), "type": "mutation", "signer": mutation.Signer(), "entity": mutation.EntityBlobRef(), "field": mutation.Field(), "time": mutation.Time()}
	switch mutation.Operation().(type) {
	case []ot.StringOperation:
		op := mutation.Operation().([]ot.StringOperation) // The following two lines work around a problem in GO/JSON
		mutJson["op"] = &op
	case []byte:
		msg := json.RawMessage(mutation.Operation().([]byte))
		mutJson["op"] = &msg
	default:
		panic("Unsupported operation kind")
	}
	schema, err := json.Marshal(mutJson)
	if err != nil {
		panic(err.String())
	}
	if self.bufferOnly {
		self.messageBuffer = append(self.messageBuffer, string(schema))
	} else {
		err = self.forwardToFollowers(perma.BlobRef(), string(schema))
	}
	if err != nil {
		log.Printf("Err Forward: %v", err)
	}
}