Created
May 7, 2021 06:29
-
-
Save monmohan/35528bff6f1b2b30b2e6a817489fbbc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func writeOps(outfile string) error { | |
f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) | |
if err != nil { | |
log.Fatalf("Failed to create file %s", err.Error()) | |
} | |
defer f.Close() | |
op1 := &typedefs.Patch_Copy{Start: 10, End: 100} | |
op2 := &typedefs.Patch_Insert{RawBytes: []byte{'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e'}} | |
ops := []*typedefs.Patch{ | |
{Op: &typedefs.Patch_CopyOp{CopyOp: op1}}, | |
{Op: &typedefs.Patch_InsertOp{InsertOp: op2}}, | |
} | |
patchins := &typedefs.Instructions{Operations: ops} | |
out, err := proto.Marshal(patchins) | |
if err != nil { | |
return err | |
} | |
_, err = f.Write(out) | |
if err != nil { | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment